#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/10/10
# @Author  : Syaoran
# @File    : app_impl.py.py
# @Desc    :

from app import db
from infrastructure.po.mode.application import Application
from loguru import logger

class ApplicationImpl(object):
    @classmethod
    def get_application_list(cls, applicationName=None, page=1, page_size=999):
        query = db.session.query(Application)
        if applicationName:
            query = query.filter(
                Application.applicationName.like(f"%{applicationName}%")
            )
        return query.paginate(page=page, per_page=page_size).items, query.count()
    
    @classmethod
    def update_application(cls, id, application_name, status, description):
        """
        更新应用信息
        :param id: 应用ID
        :param application_name: 应用名称
        :param status: 状态
        :param description: 描述
        :return:
        """
        db.session.query(Application).filter(Application.id == id).update(
            {
                "application_name": application_name,
                "status": status,
                "description": description,
            }
        )
        db.session.commit()
        return True
    
    @classmethod
    def get_application_info(cls, id):
        """
        更新应用信息
        :param id: 应用ID
        """
        id = id.strip()
        query = db.session.query(Application).filter(Application.id == id).first()
        return query